package whf.framework.ext.helper;

import java.util.List;

import whf.framework.datasource.DataSource;
import whf.framework.datasource.impl.CollectionDataSource;
import whf.framework.ext.entity.Category;
import whf.framework.ext.entity.DictItem;
import whf.framework.meta.MetaManager;
import whf.framework.meta.entity.IProperty;
import whf.framework.meta.entity.ObjectProperty;
import whf.framework.util.Utils;

/**
 * @author king
 *
 */
public class ObjectFieldsDictHelper implements DictHelper{

	/* (non-Javadoc)
	 * @see whf.framework.ext.helper.DictHelper#getDictItems(java.lang.String)
	 */
	public DataSource<DictItem> getDictItems(String queryString) {	//queryString作为property.id
		List<DictItem> items = Utils.newArrayList();
		whf.framework.meta.entity.Object obj = MetaManager.getDefaultInstance().findByEntityClass(queryString);
		if(obj != null) {
			Category c = new Category();
			List<ObjectProperty> properties = obj.getSortedProperties();
			for(IProperty p: properties){
				items.add(new DictItem(c, p.getDisplayTitle(), p.getName()));
			}
		}
		return new CollectionDataSource<DictItem>(items);
	}

}
